package com.xinqing.test.report;

import com.alibaba.fastjson.JSON;
import com.feidee.fdcommon.authorization.AuthorizationVerify;
import com.feidee.fdcommon.authorization.model.AuthInfoModel;
import com.feidee.fdcommon.model.StringResponse;
import com.feidee.fdcommon.util.HttpUtil;
import com.xinqing.test.modle.OfflineReportParam;
import com.xinqing.test.modle.StopReportKey;
import org.apache.http.client.methods.HttpPost;

/**
 * @Author:CHQ
 * @Date:2020/9/1 10:20
 * @Description
 */
public class StopReport {
    public static void main(String args[]) throws Exception {
        long startTime = System.currentTimeMillis();

        StopReportKey reportKey = new StopReportKey("report_kntgztzhbb0322165057");

        //接口需要传输的数据data
        String data = JSON.toJSONString(reportKey);
        //分配的AccessKeyId
        String accessKeyId = "data_team";
        //分配的AccessSecret
        String accessSecret = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ6+UYiQtt2OYfyfBF8e12kjd6nnF0Zl1s23f7l+eSl07xQxoxACSXyO3aq/tF7g0IiQZev4SF7ZA/oAOIYlYo0CAwEAAQ==";

        //正式环境
        String url = "http://data.feidee.com/feidee-data-report/stoptask.do";
        //调用鉴权工具包计算鉴权信息,data不存则传空
        AuthInfoModel authInfo = AuthorizationVerify.getAuthInfo(url, data, accessKeyId, accessSecret);
        //获取GMT时间
        String date = authInfo.getDate();
        //获取加密之后的data，若传入data为空，则密文也为空
        String ciphertext = authInfo.getCiphertext();
        //获取认证信息
        String authorization = authInfo.getAuthorization();
        //构造请求
        HttpPost method = null;
        try {
            method = new HttpPost(url + "?data=" + ciphertext);
            method.setHeader("Date", date);
            method.setHeader("Authorization", authorization);
            method.setHeader("AuthVersion", "2");
            StringResponse response = HttpUtil.post(method);
            System.out.println(response.getResponseBody());
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
            System.out.println("耗时：" + (System.currentTimeMillis() - startTime));
        }


    }
}
